# Build recipe for eudev.
#
# Copyright (c) 2016-2020 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=eudev
version=3.2.9
release=1

# Set 'outdir' for a nice and well-organized output directory
outdir="${outdir}/${arch}/boot"

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=http://dev.gentoo.org/~blueness/eudev/$tarname

description="
Dynamic device management.

Udev is the device manager for the Linux 2.6 kernel series.
Its primary function is managing device nodes in /dev.

It is the successor of devfs and hotplug, which means that
it handles the /dev directory and all user space actions
when adding/removing devices, including firmware load.

This is a fork of Udev from Gentoo.
"

homepage=http://wiki.gentoo.org/wiki/Eudev
license=GPLv2+

# Source documentation
docs=COPYING
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --docdir=$docsdir \
     --enable-static=yes \
     --enable-shared=yes \
     --enable-hwdb \
     --enable-manpages \
     --enable-rule-generator \
     --disable-selinux \
     --disable-introspection \
     --build="$(cc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Move installed hwdb files under /lib
    # Reported on http://github.com/gentoo/eudev/pull/127
    mkdir -p "${destdir}/lib/udev/hwdb.d"
    mv "${destdir}/etc/udev/hwdb.d"/* "${destdir}/lib/udev/hwdb.d"

    # Make symlink for multipath
    (
        cd "${destdir}/usr/sbin" && \
        ln -sf /usr/lib${libSuffix}/udev/scsi_id .
    )

    # Install perp service for udevd(8)

    mkdir -p "${destdir}/etc/perp/udevd"

    cp -p "${worktree}/archive/eudev/rc.log" \
          "${worktree}/archive/eudev/rc.main" \
          "${destdir}/etc/perp/udevd/"

    chmod 755 "${destdir}"/etc/perp/udevd/rc.*

    # Be an active service by default
    chmod +t "${destdir}/etc/perp/udevd"

    # To handle config file(s)
    touch "${destdir}/etc/perp/udevd/.graft-config" \
          "${destdir}/etc/udev/.graft-config"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}"
}

